home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / blix / blixmenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  7.6 KB  |  299 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*________________________________________________________________________
  18.  |
  19.  | blixmenu.c - all the routines use for the pop-up
  20.  |
  21. */
  22.  
  23. #include <gl/gl.h>
  24. #include <gl/sphere.h>
  25. #include <stdio.h>
  26. #include <unistd.h>
  27. #include <strings.h>
  28. #include <limits.h>
  29.  
  30. #include "blix.h"
  31. #include "blixsound.h"
  32. #include "blixscore.h"
  33. #include "blixui.h"
  34. #include "lod.h"
  35. #include "maze.h"
  36.  
  37. extern int can_do_textures;
  38. int sginap(long ticks);
  39.  
  40. static long mymenu, lodmenu, musicmenu, scoremenu, helpmenu;
  41.  
  42. void dum(void) {
  43.     ;
  44. }
  45.  
  46. void volume_up(void) {
  47.     volume_change(1);
  48. }
  49.  
  50. void volume_down(void) {
  51.     volume_change(-1);
  52. }
  53.  
  54.  
  55. /*_________________________________________________________________________
  56.  |
  57.  | do_help - display help file
  58.  |
  59.  | the help file is a showcase 3.0 file that uses the Honesty fun font.
  60.  |
  61. */
  62.  
  63. void do_help(int help) {
  64.     FILE *f;
  65.     char cmn[512];
  66.     char fullpath[512];
  67.     strcpy(fullpath, datadir);
  68.     switch (help) {
  69.       case 1: 
  70.           strcat(fullpath, "blix.showcase");
  71.     break;
  72.       case 2:
  73.     strcat(fullpath, "blixabout.showcase");
  74.     break;
  75.       case 3:
  76.     strcat(fullpath, "blixhints.showcase");
  77.     break;
  78.     }
  79.     f = fopen(fullpath, "r");
  80.     if (f != NULL) {
  81.     fclose(f);
  82.     /* use single buffer mode for best results on 8 bit systems */
  83.     if (getgdesc(GD_BITS_NORM_DBL_RED) > 3) {
  84.         strcpy(cmn,"showcase  -v ");
  85.     } else {
  86.         strcpy(cmn,"showcase -v -b ");
  87.     }
  88.     strcat(cmn, fullpath);
  89.     fprintf(stderr, "%s: starting showcase ...\n", basename);
  90.     system(cmn);
  91.     } else {
  92.     fprintf(stderr, "%s: cannot locate help file %s\n", basename, fullpath);
  93.     }
  94. }
  95.  
  96.  
  97. void set_music(int l) {
  98.     if (l < 4) {
  99.     /* start music */
  100.     switch (l) {
  101.         case 1:
  102.         current_tune = SFX_TUNE_A;
  103.         setpup(musicmenu, 1, PUP_GREY);
  104.         setpup(musicmenu, 2, PUP_NONE);
  105.         setpup(musicmenu, 3, PUP_NONE);
  106.         setpup(musicmenu, 4, PUP_NONE);
  107.         break;
  108.         case 2:
  109.         current_tune = SFX_TUNE_B;
  110.         setpup(musicmenu, 1, PUP_NONE);
  111.         setpup(musicmenu, 2, PUP_GREY);
  112.         setpup(musicmenu, 3, PUP_NONE);
  113.         setpup(musicmenu, 4, PUP_NONE);
  114.         break;
  115.         case 3:
  116.         current_tune = SFX_TUNE_C;
  117.         setpup(musicmenu, 1, PUP_NONE);
  118.         setpup(musicmenu, 2, PUP_NONE);
  119.         setpup(musicmenu, 3, PUP_GREY);
  120.         setpup(musicmenu, 4, PUP_NONE);
  121.         break;
  122.     }
  123.     if (!playing_tune) {
  124.         toggle_tune();
  125.         sfx(current_tune);
  126.         playing_tune = 1;
  127.     } else {
  128.         toggle_tune();
  129.         sginap(CLK_TCK/4);
  130.         toggle_tune();
  131.         sfx(current_tune);
  132.     }
  133.     } else {
  134.     if (playing_tune) {
  135.         toggle_tune();
  136.         playing_tune = 0;
  137.         setpup(musicmenu, 1, PUP_NONE);
  138.         setpup(musicmenu, 2, PUP_NONE);
  139.         setpup(musicmenu, 3, PUP_NONE);
  140.         setpup(musicmenu, 4, PUP_GREY);
  141.     }
  142.     }
  143. }
  144.  
  145. void showhigh(int score) {
  146.     
  147.     save_displaymode();
  148.     showscore(1, score, 1);
  149.     restore_displaymode();
  150.     enter_redraw();
  151. }
  152.  
  153. void do_menus(void) {
  154.     disable_pop();
  155.     sfx(SFX_POP);
  156.     dopup(mymenu);
  157.     enable_pop();
  158. }
  159.  
  160. void pause_game(void) {
  161.     int i;
  162.     float v1[3];
  163.     save_displaymode();
  164.     display_scene = PAUSED;
  165.     uimode = MODE2D;
  166.     cpack(0x00000000);
  167.     switch_single();
  168.     clear();
  169.     pushmatrix();
  170.     ortho2(0,1,0,1);
  171.     lmbind(MATERIAL, 0);
  172.     /* fade in score display */
  173.     for (i=16; i>=0; i--) {
  174.     setpattern(i);
  175.     bgnqstrip();
  176.     v1[0] = 1; v1[1] = 0;cpack(0x000052ff);
  177.     v2f(v1);
  178.     v1[0] = 1; v1[1] = 1; cpack(0x000038ff);
  179.     v2f(v1);
  180.     v1[0] = 0; v1[1] = 0; cpack(0x000061ff);
  181.     v2f(v1);
  182.     v1[0] = 0; v1[1] = 1; cpack(0x000022bb);
  183.     v2f(v1);
  184.     gsync();
  185.     endqstrip();
  186.     gflush();
  187.     sginap(CLK_TCK/50);
  188.     }
  189.     draw_whatever2d();
  190.     while (do_event() == 0) {
  191.     sginap(CLK_TCK/10);
  192.     }
  193.     cpack(0x000000);
  194.     for (i=16; i>= 0; i--) {
  195.     setpattern(i);
  196.     gsync();
  197.     clear();
  198.     gflush();
  199.     sginap(CLK_TCK/50);
  200.     }
  201.     sginap(CLK_TCK/2);
  202.     popmatrix();
  203.     display_scene = GAME;
  204.     uimode = MODE3D;
  205.     restore_displaymode();
  206.     enter_redraw();    
  207. }
  208.  
  209. void do_exit() {
  210.     tune_off();
  211.     sginap(CLK_TCK/4);
  212.     sfx(SFX_END);
  213.     sginap(CLK_TCK/4);
  214.     exit_program();    
  215. }
  216.  
  217. /*_________________________________________________________________
  218.  |
  219.  | start_full_menu - make the rest of the menu entries active too
  220.  |
  221. */
  222.  
  223. void start_full_menu(void) { 
  224.     setpup(mymenu, 2, PUP_NONE);   
  225.     setpup(mymenu, 3, PUP_NONE);   
  226.     setpup(mymenu, 4, PUP_NONE);   
  227.     setpup(mymenu, 5, PUP_NONE);   
  228.     setpup(mymenu, 6, PUP_NONE);   
  229. }
  230.  
  231.  
  232. void init_menus(void) {
  233.     
  234.     lodmenu = newpup();
  235.     addtopup(lodmenu, "Display Options    %t", dum);
  236.     addtopup(lodmenu, " 0   (flat maze) %f", set_lod);
  237.     addtopup(lodmenu, " 1   (blocks) %f", set_lod);
  238.     addtopup(lodmenu, " 2   (standard) %f", set_lod);
  239.     addtopup(lodmenu, " 3   (extra light) %f", set_lod);
  240.     addtopup(lodmenu, " 4   (textures) %f", set_lod);
  241.     addtopup(lodmenu, " 5   (fine circles) %f", set_lod);
  242.     if (can_do_textures == 0) {
  243.     setpup(lodmenu, 5, PUP_GREY);
  244.     }
  245.     musicmenu = newpup();
  246.     addtopup(musicmenu, "Select Instruments %t", dum);
  247.     addtopup(musicmenu, " Bottle %f", set_music);
  248.     addtopup(musicmenu, " Asia mix %f", set_music);
  249.     addtopup(musicmenu, " Bellboard %f %l", set_music);
  250.     addtopup(musicmenu, " No music %f", set_music);
  251.     if (no_sfx) {
  252.     setpup(musicmenu, 1, PUP_GREY);
  253.     setpup(musicmenu, 2, PUP_GREY);
  254.     setpup(musicmenu, 3, PUP_GREY);
  255.     setpup(musicmenu, 4, PUP_GREY);
  256.     } else if (notune) {
  257.     setpup(musicmenu, 4, PUP_GREY); 
  258.     } else {
  259.     setpup(musicmenu, 1, PUP_GREY);
  260.     }
  261.     scoremenu = newpup();
  262.     addtopup(scoremenu, "Select Highscore %t", dum);
  263.     addtopup(scoremenu, " Best Personal Scores %f", showhigh);
  264.     addtopup(scoremenu, " Best Players on System %f", showhigh);
  265.     addtopup(scoremenu, " Best Players Worldwide %f", showhigh);
  266.     if (noworld) {
  267.     setpup(scoremenu, 3, PUP_GREY);
  268.     }
  269.     helpmenu = newpup();
  270.     addtopup(helpmenu, "Select Info %t", dum);
  271.     addtopup(helpmenu, " Blix Usage   %f", do_help);
  272.     addtopup(helpmenu, " Blix Info    %f", do_help);
  273.     addtopup(helpmenu, " Blix Hints   %f", do_help);
  274.     
  275.     mymenu = newpup();
  276.     addtopup(mymenu, "Blix Options %t", dum);
  277.     addtopup(mymenu, " Help %m %l", helpmenu);
  278.     addtopup(mymenu, " Reset Transformations %f", reset_transforms);
  279.     addtopup(mymenu, " Stop Spinning %f", stop_spin);
  280.     addtopup(mymenu, " Pause Game %f %l", pause_game);
  281.     addtopup(mymenu, " Level of Detail %m %l", lodmenu);
  282.     addtopup(mymenu, " Show Highscore %m %l", scoremenu);
  283.     addtopup(mymenu, " Sound %m", musicmenu);
  284.     addtopup(mymenu, "     Louder %f", volume_up);
  285.     addtopup(mymenu, "     Softer %f %l", volume_down);
  286. #ifdef BUILDNODES
  287.     addtopup(mymenu, " Report On/Off %f", toggle_report);
  288.     addtopup(mymenu, " Zbuffer On/Off %f %l", toggle_zbuf);
  289.     addtopup(mymenu, " Read Maze %f %l", build_again);
  290.     addtopup(mymenu, " Write path %f %l", write_nodes);
  291. #endif
  292.     addtopup(mymenu, " Exit Program %f", do_exit);
  293.     setpup(mymenu, 2, PUP_GREY);   
  294.     setpup(mymenu, 3, PUP_GREY);   
  295.     setpup(mymenu, 4, PUP_GREY);   
  296.     setpup(mymenu, 5, PUP_GREY);   
  297.     setpup(mymenu, 6, PUP_GREY);   
  298. }
  299.